import {createRouter,createWebHashHistory} from 'vue-router'
import { isMobile } from '/src/utils/mobile.js'
import { getPageTitle } from '/src/utils/getPageTitle.js'

//移动端路由
const routes = [
	// {
	// 	path: '/',
	// 	name:'home',
	// 	redirect:'/home',
	// 	meta:{title:'首页'},
	// 	component: ()=> import("../views/home/home.vue") ,
	// 	children:[{
	// 		path: '/login',
	// 		name:'login',
	// 		meta:{title:'登录'},
	// 		component: ()=> import("../views/home/login.vue") 
	// 	},{ 
	// 		path: '/',
	// 		name:'home',
	// 		meta:{title:'首页'},
	// 		component: { template: '<div>Home</div>' }
	// 	},{
	// 		path: '/register',
	// 		name:'register',
	// 		meta:{title:'用户注册'},
	// 		component: ()=> import("../views/home/register.vue") 
	// 	}]
	// }
]

//企业端路由
const enterprise_routes = [{
		path: '/enterprise',
		name:'enterprise',
		redirect:'/enterprise/home',
		meta:{title:'企业端首页'},
		component: ()=> import("../views/enterprise/index.vue"),
		children:[
			{
				path: '/login',
				name:'login',
				meta:{title:'企业端登录'},
				component: ()=> import("../views/admin/login.vue") 
			},{
				path: '/register',
				name:'register',
				meta:{title:'企业端注册'},
				component: ()=> import("../views/enterprise/register.vue") 
			},{
				path: 'home',
				name:'home',
				meta:{title:'企业端首页'},
				component: ()=> import("../views/enterprise/home.vue")
			}
		]
	}]

//管理员路由
const admin_routes = [{
	path: '/admin',
	name:'admin',
	redirect:'/admin/home',
	meta:{title:'管理端首页'},
	component: ()=> import("../views/admin/index.vue"),
	children:[{

	}]
}]

const router = createRouter({
	history: createWebHashHistory(),
	routes
})

const token={
	//客户（求职者）token
	work_token:'',
	//企业token
	enterprise_token:'',
	//管理员token
	admin_token:''
}
router.beforeEach((to, from, next) => {
	document.title = getPageTitle(to.meta.title);
	
	// 判断有没有登录
	token.home = sessionStorage.getItem('home_token');
	token.enterprise = sessionStorage.getItem('enterprise_token');
	token.admin = sessionStorage.getItem('admin_token');

	// if ([`/home/login`,`/home/register`].indexOf(to.path)!=-1 || [`/enterprise/login`,`/enterprise/register`].indexOf(to.path)!=-1 || [`/admin/login`,`/admin/register`].indexOf(to.path)!=-1) {  //登录注册无需登录
	// 	next();
	// } else {
	// 	if (token.home === null) {   //未登录跳转登录
	// 		next(`/home/login`);
	// 	} else if(token.enterprise === null){
	// 		next(`/enterprise/login`);
	// 	}else if(token.admin === null){
	// 		next(`/admin/login`);
	// 	}else{
	// 		next();
	// 	}
	// }
	
 });

export default router